/**
 * 获取本机IP地址
 */

const os = require('os');

function getLocalIPs() {
  const interfaces = os.networkInterfaces();
  const ips = [];

  for (const name of Object.keys(interfaces)) {
    for (const interface of interfaces[name]) {
      // 跳过内部地址和非IPv4地址
      if (interface.family === 'IPv4' && !interface.internal) {
        ips.push({
          name: name,
          address: interface.address,
          netmask: interface.netmask
        });
      }
    }
  }

  return ips;
}

console.log('🌐 本机网络接口信息:');
console.log('');

const ips = getLocalIPs();

if (ips.length === 0) {
  console.log('❌ 未找到可用的网络接口');
} else {
  ips.forEach((ip, index) => {
    console.log(`${index + 1}. ${ip.name}`);
    console.log(`   IP地址: ${ip.address}`);
    console.log(`   子网掩码: ${ip.netmask}`);
    console.log(`   访问地址: http://${ip.address}:5173/`);
    console.log('');
  });
}

console.log('💡 使用方法:');
console.log('1. 确保前端项目已启动 (npm run dev)');
console.log('2. 在同一网络的其他设备上访问上述地址');
console.log('3. 确保防火墙允许5173端口访问');
